
/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package org.mca.mcaweb.util;

import java.awt.event.KeyEvent;

import javax.persistence.EntityManager;
import javax.persistence.EntityManagerFactory;
import javax.persistence.Persistence;
import javax.persistence.Query;

public class util {

    public static String lpad(String valueToPad, String filler, int size) {
        while (valueToPad.length() < size) {
            valueToPad = filler + valueToPad;
        }
        return valueToPad;
    }

    public static String rpad(String valueToPad, String filler, int size) {
        while (valueToPad.length() < size) {
            valueToPad = valueToPad + filler;
        }
        return valueToPad;
    }

//    public class MyKeyListener2 extends KeyAdapter {
    public boolean keyPressed(KeyEvent ke) {
        if (ke.getKeyCode() == KeyEvent.VK_ENTER) {
            //É ENTER
            return true;
        } else {
            //Não é ENTER
            return true;
        }
    }

    public static String CambioDia(String codigoMoeda) {
        EntityManager em;
        EntityManagerFactory emf = Persistence.createEntityManagerFactory("MCASHOPWEBPU");
        em = emf.createEntityManager();
        Query qry = em.createNativeQuery("select cota.cotavalor from cota INNER JOIN moed ON       moed.moedcodigo = cota.moedcodigo  WHERE  cota.moedcodigo  = :param1 AND rownum <= 1 ORDER BY cota.cotadata DESC");
        qry.setParameter("param1", codigoMoeda);
        return qry.getSingleResult().toString();
    }
}

